<template>
	<view class="container">
		<!-- 顶部用户信息 -->
		<view class="user-section">
			<u-avatar :src="src" shape="square" class="tx"></u-avatar>
			<text class="tex" style="color: aliceblue;">{{name}}</text>
		</view>

		<!-- 菜单列表 - 使用普通view代替u-list -->
		<view class="menu-section">
			<!-- 第一组 -->
			<view class="menu-item" @click="click1">
				<text>个人资料</text>
			</view>
			<view class="menu-item" @click="click2">
				<text>个人动态</text>
			</view>

			<!-- 分隔线 -->
			<view class="divider"></view>

			<!-- 第二组 -->
			<view class="menu-item">
				<text>消息</text>
			</view>

			<!-- 分隔线 -->
			<view class="divider"></view>

			<!-- 第三组 -->
			<view class="menu-item">
				<text>设置</text>
			</view>
			<view class="menu-item">
				<text>反馈</text>
			</view>
			<view class="menu-item">
				<text>关于</text>
			</view>

			<!-- 分隔线 -->
			<view class="divider"></view>

			<!-- 退出按钮 -->
			<view>
				<u-button type="error" text="退出登录" @click="loginOut"></u-button>
			</view>
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>
<script>
	import http from "../../http.js"
	export default {
		data() {
			return {
				showSex: false,
				src: "",
				list: [],
				name: '',
				show: false,
				title: '标题',
				content: 'uView的目标是成为uni-app生态最优秀的UI框架'
			}
		},
		onLoad() {
			this.getList()
		},
		methods: {
			getList() {
				http({
					url: "/api/student/user/current",
					method: "post",

				}).then(res => {
					console.log(res);
					if (res.code === 1) {
						this.list = res.response
						this.src = res.response.imagePath
						this.name = res.response.realName
					}
				})
			},
			click1() {
				uni.navigateTo({
					url: "/pages/usermsg/usermsg"
				})
			},
			click2() {
				uni.navigateTo({
					url: "/pages/PersonalDate/PersonalDate"
				})
			},
			onShow() {
				this.getList()
			},
			//退出
			loginOut() {
				http({
					url: "/api/user/logout",
					method: "post"
				}).then(res => {

					// 确认对话框
					uni.showModal({
						title: '提示',
						content: '确定要退出登录吗？',
						success: (res) => {
							if (res.confirm) {
								this.$refs.uToast.show({
									type: "success",
									message: "退出成功",
									duration: 1000,
									complete() {
										uni.navigateTo({
											url: "/pages/login/login"
										})
									}
								})
							} else {
								this.$refs.uToast.show({
									type: "error",
									message: res.message,
									duration: 1000,
								})
							}
						}
					});

				})
			}

		}
	}
</script>

<style lang="scss" scoped>
	.container {
		padding: 30rpx;
		background-color: #f5f5f5;
		min-height: 100vh;
	}

	.user-section {
		padding: 40rpx 0;
		text-align: center;
		display: flex;
		align-items: center;
		background-color: #648ADD;

		.tex {
			margin-left: 30rpx;
		}

		.tx {
			margin-left: 30rpx;
		}

		.username {
			font-size: 36rpx;
			font-weight: bold;
		}
	}

	.menu-section {
		background-color: #fff;
		border-radius: 12rpx;
		overflow: hidden;

		.menu-item {
			padding: 28rpx 30rpx;
			font-size: 32rpx;
			position: relative;

			&:not(:last-child):not(.logout)::after {
				content: '';
				position: absolute;
				left: 30rpx;
				right: 0;
				bottom: 0;
				height: 1px;
				background-color: #f5f5f5;
			}

			&.logout {
				color: #f56c6c;
				text-align: center;
			}
		}

		.divider {
			height: 20rpx;
			background-color: #f5f5f5;
		}
	}
</style>